#ifndef _CMD_CORE_H_
#define _CMD_CORE_H_

#include <stddef.h>
#include "list.h"

#ifdef __cplusplus
extern "C"{
#endif

#define MAX_CMD_LEN 16
#define MAX_MODULE_NAME_LEN 16

#define DEF_CMD(MODULE,CMD) {#CMD,MODULE##_exec_##CMD}
#define PARSE_FUN(MODULE,CMD) MODULE##_parse_##CMD
#define EXEC_FUN(MODULE,CMD) MODULE##_exec_##CMD

typedef int (*parse_fun_t)(char *cmd_line);
typedef int (*exec_fun_t)(char *cmd_line, char *ret_buf, size_t ret_max_len);

typedef struct module_node
{
	char module_name[MAX_MODULE_NAME_LEN+1];
	list_t *cmd_list;
}module_node_t;

typedef struct cmd_process{
	char cmd[MAX_CMD_LEN];
	exec_fun_t exec_fun;
}cmd_process_t;

int init_module_core();
int register_module(module_node_t *module_node);
int register_module_byname(char *module_name);
int register_modules_auto_end(module_node_t *module_node);
int register_modules_auto_end_byname(char **module_name);
int init_cmd_list(list_t **cmd_list);
int register_cmd(list_t *cmd_list, cmd_process_t *cmd_process);
int register_cmds(list_t *cmd_list,cmd_process_t *cmd_process, size_t num);
int register_cmds_auto_end(char *module_name, cmd_process_t *cmd_process);
int execute(char *cmd_line, char *ret_buf, size_t ret_max_len);
int execute_cmd_line(list_t *cmd_list, char *cmd_line, char *ret_buf, size_t ret_max_len);
list_node_t * find_module_node_in_list(list_t *module_list, char *module);
list_node_t * find_cmd_node_in_list(list_t *cmd_list, char *cmd);
int match_cmd(void *a, void *b);
int match_module(void *a, void *b);
void print_module(void *val);
void print_cmd(void *val);
void release_list(list_t **list);

#ifdef __cplusplus
}
#endif

#endif
